<template>
	<view>
				<uni-list>
			<uni-list-item v-for="(item,index) in items" :key="index" :title="item.c_name" note="def" showArrow="true"
				clickable @tap="todetail(item)"></uni-list-item>
		</uni-list>
		<view>
			<uni-fab :pattern="pattern" :content="content" :horizontal="horizontal" :vertical="vertical"
				:direction="direction" @trigger="trigger" @fabClick="fabClick" ></uni-fab>
		</view>

	</view>
</template>

<script>

	export default {
		data() {
			return {
				pattern: {
						},
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				popMenu: false,
				content: [],
				items: [{
					id: 1,
					name: '1abc'
				}, {
					id: 2,
					name: '2abc'
				}, {
					id: 3,
					name: '3abc'
				}, {
					id: 4,
					name: '4abc'
				}, {
					id: 5,
					name: '5abc'
				}, {
					id: 6,
					name: '6abc'
				}, ],
				pagination: {
					pagerCount: 0,
					count: 0,
					pageIndex: 1,
					limit: 9
				}
			}
		},
		onLoad() {
			console.log(this.apiUrl)
			// this.getList(this.pagination)
		},
		onShow() {
			this.getList(this.pagination)
		},
		mounted() {
			uni.getSystemInfo({
				success(res) {
					console.log(res)
				}
			})
		},
		// onReachBottom() {
		// 		console.log(Math.ceil(this.pagination.count / this.pagination.limit), this.pagination.pageIndex)
		// 	if (Math.ceil(this.pagination.count / this.pagination.limit) >= this.pagination.pageIndex) {		
		// 	uni.showToast({
		// 		icon: 'none',
		// 		title: '加载下一页'
		// 	})

		// 		this.pagination.pageIndex++
		// 		this.getList(this.pagination)

		// 	} else {
		// 		uni.showToast({
		// 			icon: 'none',
		// 			title: '到底了'
		// 		})
		// 	}

		// },
		onPullDownRefresh() {
			this.refresh()
		},
		methods: {
			trigger(e) {
				console.log(e);

			},
			fabClick(e) {
				console.log(1111)
				uni.navigateTo({
					url: '/pages/customeradd/customeradd',
				});
			},
			refresh() {
				console.log(Math.ceil(this.pagination.count / this.pagination.limit), this.pagination.pageIndex)
				if (Math.ceil(this.pagination.count / this.pagination.limit) > this.pagination.pageIndex) {
					uni.showToast({
						icon: 'none',
						title: '加载下一页'
					})

					this.pagination.pageIndex++
					this.getList(this.pagination)

				} else {
					uni.showToast({
						icon: 'none',
						title: '到底了'
					})
				}
				uni.stopPullDownRefresh()
			},
			getList(val) {
				uni.request({
					url: `${this.apiUrl}/rest/ad?page=${val.pageIndex}&limit=${val.limit}`,
					method: 'GET',
					data: {},
					success: (res) => {
						this.items = res.data.rows;
						this.pagination.count = res.data.count
						console.log(this.items)
					},
					fail: () => {

					},
					complete: () => {

					}
				})
			},
			todetail(e) {
				// uni.showToast({
				// 	title: e.c_name,
				// 	icon: 'none'
				// })
				// method one
				// uni.navigateTo({
				// 	url:'/pages/customerdetail/customerdetail?c_id=' + e.c_id
				// })

				// method tow :  uni.$emit uni.$on

				// uni.$emit('update',{msg:'页面更新'});
				// uni.$on给数据赋值视图没更新 解决办法：给uni.$emit设置延时
				setTimeout(() => {
					uni.$emit('update', {
						msg: '页面更新'
					})
				}, 100);
				uni.navigateTo({
					url: '/pages/customerset/customerset',
					// url:'/pages/customerdetail/customerdetail',
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('send', {
							...e
						})
					}
				});

			}
		}
	}
</script>

<style>

</style>
